package org.jeecg.modules.compilation.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.Md5Util;
import org.jeecg.config.shiro.filters.JwtFilter;
import org.jeecg.modules.compilation.entity.CiBusinessCategory;
import org.jeecg.modules.compilation.entity.CiBusinessCategoryUser;
import org.jeecg.modules.compilation.service.ICiBusinessCategoryUserService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 用户icon关联表
 * @Author: jeecg-boot
 * @Date:   2024-03-15
 * @Version: V1.0
 */
@Api(tags="用户icon关联表")
@RestController
@RequestMapping("/compilation/ciBusinessCategoryUser")
@Slf4j
public class CiBusinessCategoryUserController extends JeecgController<CiBusinessCategoryUser, ICiBusinessCategoryUserService> {
	@Autowired
	private ICiBusinessCategoryUserService ciBusinessCategoryUserService;

	/**
	* 首页查询用户图标列表（根据用户id获取数据，一开始前8个是默认显示：enableFlag=1）
	* @return
	*/
	@AutoLog(value = "首页查询用户图标列表")
	@ApiOperation(value="首页查询用户图标列表", notes="首页查询用户图标列表")
	@GetMapping("/getIconList")
	public Result<List<CiBusinessCategoryUser>> getIconList(){
	 //获取图标列表
	 List<CiBusinessCategoryUser> ciBusinessCategoryUserList = ciBusinessCategoryUserService.getIconList();
	 return Result.OK(ciBusinessCategoryUserList);
	}

	/**
	 * 新增图标
	 */
	@AutoLog(value = "新增图标")
	@ApiOperation(value="新增图标", notes="新增图标")
	@GetMapping("/addIcon")
	public Result<List<CiBusinessCategory>> addIcon(){
		//根据 用户id、enableFlag=0 查询数据
		List<CiBusinessCategory> ciBusinessCategoryList = ciBusinessCategoryUserService.addIcon();
		return Result.ok(ciBusinessCategoryList);
	}

	/**
	 *
	 * @param businessCategorySn 图标编号
	 * @return
	 */
	 @AutoLog(value = "更改图标状态")
	 @ApiOperation(value="更改图标状态", notes="更改图标状态")
	 @GetMapping("/updateIcon")
	 public Result<String> deleteIcon(@RequestParam String businessCategorySn){
		boolean flag = ciBusinessCategoryUserService.updateIcon(businessCategorySn);
		if(flag) {
			return Result.OK("状态更新成功");
		}
		return Result.error("状态更新失败");
	 }






	/**------------------------------------------------------------------------------------------------*/

	/**
	 * 分页列表查询
	 *
	 * @param ciBusinessCategoryUser
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "用户icon关联表-分页列表查询")
	@ApiOperation(value="用户icon关联表-分页列表查询", notes="用户icon关联表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<CiBusinessCategoryUser>> queryPageList(CiBusinessCategoryUser ciBusinessCategoryUser,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<CiBusinessCategoryUser> queryWrapper = QueryGenerator.initQueryWrapper(ciBusinessCategoryUser, req.getParameterMap());
		Page<CiBusinessCategoryUser> page = new Page<CiBusinessCategoryUser>(pageNo, pageSize);
		IPage<CiBusinessCategoryUser> pageList = ciBusinessCategoryUserService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param ciBusinessCategoryUser
	 * @return
	 */
	@AutoLog(value = "用户icon关联表-添加")
	@ApiOperation(value="用户icon关联表-添加", notes="用户icon关联表-添加")
//	@RequiresPermissions("compilation:ci_business_category_user:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody CiBusinessCategoryUser ciBusinessCategoryUser) {
		ciBusinessCategoryUserService.save(ciBusinessCategoryUser);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param ciBusinessCategoryUser
	 * @return
	 */
	@AutoLog(value = "用户icon关联表-编辑")
	@ApiOperation(value="用户icon关联表-编辑", notes="用户icon关联表-编辑")
//	@RequiresPermissions("compilation:ci_business_category_user:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody CiBusinessCategoryUser ciBusinessCategoryUser) {
		ciBusinessCategoryUserService.updateById(ciBusinessCategoryUser);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "用户icon关联表-通过id删除")
	@ApiOperation(value="用户icon关联表-通过id删除", notes="用户icon关联表-通过id删除")
//	@RequiresPermissions("compilation:ci_business_category_user:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		ciBusinessCategoryUserService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "用户icon关联表-批量删除")
	@ApiOperation(value="用户icon关联表-批量删除", notes="用户icon关联表-批量删除")
//	@RequiresPermissions("compilation:ci_business_category_user:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.ciBusinessCategoryUserService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "用户icon关联表-通过id查询")
	@ApiOperation(value="用户icon关联表-通过id查询", notes="用户icon关联表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<CiBusinessCategoryUser> queryById(@RequestParam(name="id",required=true) String id) {
		CiBusinessCategoryUser ciBusinessCategoryUser = ciBusinessCategoryUserService.getById(id);
		if(ciBusinessCategoryUser==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(ciBusinessCategoryUser);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param ciBusinessCategoryUser
    */
//    @RequiresPermissions("compilation:ci_business_category_user:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CiBusinessCategoryUser ciBusinessCategoryUser) {
        return super.exportXls(request, ciBusinessCategoryUser, CiBusinessCategoryUser.class, "用户icon关联表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
//    @RequiresPermissions("compilation:ci_business_category_user:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CiBusinessCategoryUser.class);
    }

}
